/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
var isSubCatVisible = false;
var selectedCity=0;
var selectedSubCategory;
function hideSubCategories(){
    isSubCatVisible = false;
    $('#subCategories').hide();
}
function showSubCategories(alink){
    var pos = findPos(alink);
    $('#subCategories').load('SubCategoryServlet?catid='+alink.id);
    if(isSubCatVisible){
        $('#subCategories').hide();
        isSubCatVisible = false;
    }else{
        var position = $('#subCategories').position();
        $('#subCategories').css({position:'absolute',top:pos[1]-12,left:pos[0]+158});
        $('#subCategories').show();
        isSubCatVisible = true;
    }
    
   // alert(pos[1]+" - "+pos[0]);
     
    //$('#subCategories').style.position = "absolute";
    //position.top = pos[1];
    //position.left = pos[0]+1;
}

function showSubCategoriesAdmin(sel){
    //window.open('/1.0.0/SubCategoryAdminServlet?catid='+sel.options[sel.selectedIndex].id);
    $('#subCategoriesAdmin').load('/1.0.0/SubCategoryAdminServlet?catid='+sel.options[sel.selectedIndex].id);
    //alert("loaded");
}

function loadItems(){
    //alert('ItemServlet?subcatid='+selectedSubCategory+"&cityId="+selectedCity);
    if(selectedCity == "undefined" || selectedCity<=0)
        {
            alert("Please select a City");
        }
    $('.center_prod_box_big').load('ItemServlet?subcatid='+selectedSubCategory+"&cityId="+selectedCity);
    //alert("loaded");
}

function setSelectedCity(sel){
    selectedCity = sel.options[sel.selectedIndex].id;
}

function findPos(obj)
{

    var curleft = curtop = 0;

    if (obj.offsetParent) {
        curleft = obj.offsetLeft

        curtop = obj.offsetTop

        while (obj = obj.offsetParent) {
            curleft += obj.offsetLeft

            curtop += obj.offsetTop

        }

    }

    //alert(curleft + " " + curtop);
    return [curleft,curtop];
}

